
num=int(input())

grades={}

for row in range(num):
    temp=input().split()
    team, _ =temp[0].split('-')
    grades.setdefault(team,0)
    grades[team]+=int(temp[1])

ans=max(grades.items(),key=lambda x:x[1])  #57ms 3072KB 10Min
print(*ans)
# ans=sorted(grades.items(),key=lambda x:x[1])  #62ms 3204KB 10Min
# print (*ans[-1])